package cn.hxlc.tie.demo.modular.station.controlller;


import cn.hxlc.tie.demo.modular.station.model.param.UserParam;
import cn.hxlc.tie.demo.modular.station.service.UserService;
import cn.hxlc.tie.libs.scanner.annotation.GetResource;
import cn.hxlc.tie.libs.scanner.annotation.PostResource;
import cn.hxlc.tie.libs.scanner.stereotype.ApiResource;
import cn.hxlc.tie.model.web.response.ResponseData;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@ApiResource(name = "用户管理", path = "/user")
@Api(tags = "用户")
public class DataManagerController {

    @Autowired
    private UserService userService;


    @PostResource(name = "新增", path = "/add",requiredPermission=false, requiredLogin = false)
    public ResponseData add(@RequestBody UserParam userParam) {
        userService.add(userParam);
        return ResponseData.success(ResponseData.DEFAULT_SUCCESS_CODE,"新增成功",null);
    }

    @GetResource(name = "查询所有", path = "/findAll", requiredPermission=false, requiredLogin = false)
    public ResponseData findAll(UserParam userParam) {

        return ResponseData.success(userService.findAll(userParam));
    }
    @GetResource(name = "查询日期", path = "/findDate/{id}", requiredPermission=false, requiredLogin = false)
    public ResponseData findDate(@PathVariable("id") int id) {

        return ResponseData.success(userService.findDate(id));
    }
    @GetResource(name = "详情", path = "/findByOne/{id}", requiredPermission=false, requiredLogin = false)
    public ResponseData findByOne(@PathVariable("id") int id) {

        return ResponseData.success(userService.findByOne(id));
    }
    @PostResource(name = "修改", path = "/update")
    public ResponseData updateById(@RequestBody UserParam userParam) {
        userService.updateByOne(userParam);
        return ResponseData.success(ResponseData.DEFAULT_ERROR_CODE,"修改成功",null);
    }
    @PostResource(name = "修改", path = "/updateDate")
    public ResponseData updateDate(@RequestBody UserParam userParam) {
        userService.updateDate(userParam);
        return ResponseData.success(ResponseData.DEFAULT_ERROR_CODE,"修改成功",null);
    }

    @PostResource(name = "删除", path = "/delete", requiredPermission=false, requiredLogin = false)
    public ResponseData delete(@RequestBody UserParam userParam) {
        userService.delete(userParam.getId());
        return ResponseData.success(ResponseData.DEFAULT_ERROR_CODE,"删除成功",null);

    }
    @PostResource(name = "批量删除", path = "/batchDelete", requiredPermission=false, requiredLogin = false)
    public ResponseData batchDelete(@RequestBody List<Integer> ids) {
        userService.batchDelete(ids);
        return ResponseData.success(ResponseData.DEFAULT_ERROR_CODE,"删除成功",null);

    }

    @GetResource(name = "分页查询", path = "/queryListPage", requiredPermission=false, requiredLogin = false)
    public ResponseData queryListPage(UserParam userParam) {

        return ResponseData.success( userService.queryListPage(userParam));
    }




}
